import com.beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        //1.先得到上下文对象
        ApplicationContext context=new ClassPathXmlApplicationContext("spring-config.xml");
        //2.得到bean
        //controller注解
      //  UserController controller=context.getBean("userController",UserController.class);
        //3.使用bean
       // controller.sayHi();

         //service注解
        //UserService userService=context.getBean(UserService.class);
       // userService.sayHi();

        //repository注解
       // UserRepository repository=context.getBean(UserRepository.class);
        //repository.sayHi();

        //Config 注解
        //UserConfig config=context.getBean(UserConfig.class);
       // config.sayHi();

        //component注解
       // UserComponent component=context.getBean(UserComponent.class);
       // component.sayHi();

        //@bean注解
      //  User user=context.getBean("user1",User.class);
       // System.out.println(user);


        //属性注入
        //UserController2 userController2=context.getBean(UserController2.class);
       // userController2.sayHi();

        //构造方法注入
      ////UserController3 userController3=context.getBean(UserController3.class);
      //userController3.sayHi();

      //setter注入
        UserController4 userController4=context.getBean(UserController4.class);
        userController4.sayHi();


        //bean 的作用域
       BeanScope1 beanScope1=context.getBean(BeanScope1.class);
       User user1=beanScope1.getUser();
        System.out.println("beanscope1"+user1);

        BeanScope2 beanScope2=context.getBean(BeanScope2.class);
        User user2=beanScope2.getUser();

        System.out.println("beanscope2"+user2);

    }
}
